package com.hyou.starter.autoconfigure.datasource.hikari;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.hyou.common.base.BaseBean;

/**
 * HikariCP数据源配置
 * 
 * @author FengChangshuo
 * @version 1.0.0 2018-05-21 11:13:35 初始创建
 */
public class HikariDataSourceProp extends BaseBean {

    /**
     * serialVersionUID
     */
    private static final long serialVersionUID = 4676536528809236515L;
    
    /**
     * 数据库连接驱动类
     */
    private String driverClassName = "com.mysql.jdbc.Driver";
    
    /**
     * <pre>
     * 数据库连接URL
     * 
     * This property directs HikariCP to use "DriverManager-based" configuration. 
     * We feel that DataSource-based configuration (above) is superior for a variety of reasons (see below), 
     * but for many deployments there is little significant difference. 
     * When using this property with "old" drivers, you may also need to set the driverClassName property, 
     * but try it first without. 
     * Note that if this property is used, you may still use DataSource properties to configure your driver 
     * and is in fact recommended over driver parameters specified in the URL itself. 
     * Default: none
     * </pre>
     */
    private String jdbcUrl;
    
    /**
     * <pre>
     * 数据库登录用户名
     * 
     * This property sets the default authentication username used when obtaining Connections from the underlying driver. 
     * Note that for DataSources this works in a very deterministic fashion 
     * by calling DataSource.getConnection(*username*, password) on the underlying DataSource. 
     * However, for Driver-based configurations, every driver is different. 
     * In the case of Driver-based, HikariCP will use this username property to set a user property in the Properties 
     * passed to the driver's DriverManager.getConnection(jdbcUrl, props) call. 
     * If this is not what you need, skip this method entirely and call addDataSourceProperty("username", ...), 
     * for example. Default: none
     * </pre>
     */
    private String username;
    
    /**
     * <pre>
     * 数据库登录密码
     * 
     * This property sets the default authentication password used when obtaining Connections from the underlying driver. 
     * Note that for DataSources this works in a very deterministic fashion 
     * by calling DataSource.getConnection(username, *password*) on the underlying DataSource. 
     * However, for Driver-based configurations, every driver is different. In the case of Driver-based, 
     * HikariCP will use this password property to set a password property in the Properties passed to the driver's 
     * DriverManager.getConnection(jdbcUrl, props) call. 
     * If this is not what you need, skip this method entirely and call addDataSourceProperty("pass", ...), 
     * for example. Default: none
     * </pre>
     */
    @JsonIgnore
    private String password;
    
    /**
     * <pre>
     * 等待连接池分配连接的最大时长（毫秒），超过这个时长还没可用的连接则发生SQLException， 缺省:30秒
     * 
     * This property controls the maximum number of milliseconds that a client (that's you) will wait for a connection 
     * from the pool. 
     * If this time is exceeded without a connection becoming available, a SQLException will be thrown. 
     * Lowest acceptable connection timeout is 250 ms. 
     * Default: 30000 (30 seconds)
     * </pre>
     */
    private long connectionTimeout = 30000;
    
    /**
     * <pre>
     * 一个连接idle状态的最大时长（毫秒），超时则被释放（retired），缺省:10分钟
     * 
     * This property controls the maximum amount of time that a connection is allowed to sit idle in the pool. 
     * This setting only applies when minimumIdle is defined to be less than maximumPoolSize. 
     * Idle connections will not be retired once the pool reaches minimumIdle connections. 
     * Whether a connection is retired as idle or not is subject to a maximum variation of +30 seconds, 
     * and average variation of +15 seconds. 
     * A connection will never be retired as idle before this timeout. 
     * A value of 0 means that idle connections are never removed from the pool. 
     * The minimum allowed value is 10000ms (10 seconds). Default: 600000 (10 minutes)
     * </pre>
     */
    private long idleTimeout = 600000;
    
    /**
     * <pre>
     * 一个连接的生命时长（毫秒），超时而且没被使用则被释放（retired），缺省:30分钟，
     * 建议设置比数据库超时时长少30秒，参考MySQL wait_timeout参数（show variables like '%timeout%';）
     * 
     * This property controls the maximum lifetime of a connection in the pool. 
     * An in-use connection will never be retired, only when it is closed will it then be removed. 
     * On a connection-by-connection basis, minor negative attenuation is applied to avoid mass-extinction in the pool. 
     * We strongly recommend setting this value, and it should be several seconds shorter than any database or 
     * infrastructure imposed connection time limit. 
     * A value of 0 indicates no maximum lifetime (infinite lifetime), subject of course to the idleTimeout setting. 
     * Default: 1800000 (30 minutes)
     * </pre>
     */
    private long maxLifetime = 1800000;
    
    /**
     * <pre>
     * If your driver supports JDBC4 we strongly recommend not setting this property. 
     * This is for "legacy" drivers that do not support the JDBC4 Connection.isValid() API. 
     * This is the query that will be executed just before a connection is given to you from the pool 
     * to validate that the connection to the database is still alive. 
     * Again, try running the pool without this property, HikariCP will log an error if your driver is not JDBC4 
     * compliant to let you know. Default: none
     * </pre>
     */
    private String connectionTestQuery = "select 1";
    
    /**
     * <pre>
     * This property controls the minimum number of idle connections that HikariCP tries to maintain in the pool. 
     * If the idle connections dip below this value and total connections in the pool are less than maximumPoolSize, 
     * HikariCP will make a best effort to add additional connections quickly and efficiently. 
     * However, for maximum performance and responsiveness to spike demands, we recommend not setting this value 
     * and instead allowing HikariCP to act as a fixed size connection pool. 
     * Default: same as maximumPoolSize
     * </pre>
     */
    private int minimumIdle = 10;
    
    /**
     * <pre>
     * This property controls the maximum size that the pool is allowed to reach, including both idle and in-use 
     * connections. Basically this value will determine the maximum number of actual connections to the database 
     * backend. A reasonable value for this is best determined by your execution environment. 
     * When the pool reaches this size, and no idle connections are available, calls to getConnection() will block 
     * for up to connectionTimeout milliseconds before timing out. Please read about pool sizing. Default: 10
     * </pre>
     */
    private int maximumPoolSize = 10;

    /**
     * @return 数据库连接驱动类
     */
    public String getDriverClassName() {
        return this.driverClassName;
    }

    /**
     * @param driverClassName 数据库连接驱动类
     */
    public void setDriverClassName(String driverClassName) {
        this.driverClassName = driverClassName;
    }

    /**
     * @return 数据库连接URL
     */
    public String getJdbcUrl() {
        return this.jdbcUrl;
    }

    /**
     * @param jdbcUrl 数据库连接URL
     */
    public void setJdbcUrl(String jdbcUrl) {
        this.jdbcUrl = jdbcUrl;
    }

    /**
     * @return 数据库登录用户名
     */
    public String getUsername() {
        return this.username;
    }

    /**
     * @param username 数据库登录用户名
     */
    public void setUsername(String username) {
        this.username = username;
    }

    /**
     * @return 数据库登录密码
     */
    public String getPassword() {
        return this.password;
    }

    /**
     * @param password 数据库登录密码
     */
    public void setPassword(String password) {
        this.password = password;
    }

    /**
     * @return 等待连接池分配连接的最大时长（毫秒）
     */
    public long getConnectionTimeout() {
        return this.connectionTimeout;
    }

    /**
     * @param connectionTimeoutMs 等待连接池分配连接的最大时长（毫秒）
     */
    public void setConnectionTimeout(long connectionTimeout) {
        this.connectionTimeout = connectionTimeout;
    }

    /**
     * @return 一个连接idle状态的最大时长（毫秒）
     */
    public long getIdleTimeout() {
        return this.idleTimeout;
    }

    /**
     * @param idleTimeout 一个连接idle状态的最大时长（毫秒）
     */
    public void setIdleTimeout(long idleTimeout) {
        this.idleTimeout = idleTimeout;
    }

    /**
     * @return 一个连接的生命时长（毫秒）
     */
    public long getMaxLifetime() {
        return this.maxLifetime;
    }

    /**
     * @param maxLifetime 一个连接的生命时长（毫秒）
     */
    public void setMaxLifetime(long maxLifetime) {
        this.maxLifetime = maxLifetime;
    }

    /**
     * @return the connectionTestQuery
     */
    public String getConnectionTestQuery() {
        return this.connectionTestQuery;
    }

    /**
     * @param connectionTestQuery the connectionTestQuery to set
     */
    public void setConnectionTestQuery(String connectionTestQuery) {
        this.connectionTestQuery = connectionTestQuery;
    }

    /**
     * @return the minimumIdle
     */
    public int getMinimumIdle() {
        return this.minimumIdle;
    }

    /**
     * @param minimumIdle the minimumIdle to set
     */
    public void setMinimumIdle(int minimumIdle) {
        this.minimumIdle = minimumIdle;
    }

    /**
     * @return the maximumPoolSize
     */
    public int getMaximumPoolSize() {
        return this.maximumPoolSize;
    }

    /**
     * @param maximumPoolSize the maximumPoolSize to set
     */
    public void setMaximumPoolSize(int maximumPoolSize) {
        this.maximumPoolSize = maximumPoolSize;
    }
    
}
